package com.base.jdk8.lambda;


import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class FilterStrings {
    public static List<String> filter(List<String> srcList, Predicate<String> p) {
        List<String> newList = new ArrayList<>();
        for (String str : srcList) {
            if (p.test(str)) {
                newList.add(str);
            }
        }
        return newList;
    }

    public static List<String> filter(List<String> srcList) {
        List<String> newList = new ArrayList<>();
        for (String str : srcList) {
            if (StringUtils.isNotBlank(str)) {
                newList.add(str);
            }
        }
        return newList;
    }


    public static void main(String[] args) {
        List<String> strings = new ArrayList<>();
        strings.add("berijing");
        strings.add("shanghai");
        strings.add("  ");
        strings.add(null);

        Predicate<String> p = (string) -> StringUtils.isBlank(string);
        List<String> resultList = filter(strings, p);
        System.out.println("resultList = " + resultList);

    }
}
